package com.cas.object;

import java.util.List;

import com.cas.scalls.util.SqliteUtil;

public class Commond_Maker {
///////////////////////change time/////////////////////////////
	static byte[] makeChangeTimeCommond(String time)
	{
	    byte[] rSendBuf = null;
	    return rSendBuf;
	}

	//////////////////////download plu////////////////////////////
	List<byte[]> makeDownloadPluCommond(List<Plu> plulist) throws Exception
	{
	    //Download_Plu_Commond.saveOrUpdatePlu(plulist);
	    return Download_Plu_Commond.makeCommondToScale(plulist);
	}

	//////////////////////upload sale/////////////////////////////
	List<byte[]> makeUploadSalesInfoCommond()
	{
	    return Upload_Sale_Commond.makeCommondToScale();
	}
//	String makeSaleXmlForPc(List<Upload_Sale> salelist)
//	{
//	    return Upload_Sale_Commond.makeCommndToPc(salelist);
//	}
	String makeSaleXmlForPc(List<byte[]> salelist,String ipaddr) throws Exception
	{
	    return Upload_Sale_Commond.makeCommndToPc(salelist, ipaddr);
	}
	List<Upload_Sale> saveSalesAndUpdate(List<byte[]> salelist,SqliteUtil sqlutil,String ipaddr) throws Exception
	{
	    return Upload_Sale_Commond.saveInfoAndUpdate(salelist ,ipaddr);
	}
	void updateSalesUploadedItems(List<Upload_Sale> uslist,SqliteUtil sqlutil,String ipaddr) throws Exception
	{
	    Upload_Sale_Commond.updateUploadedItems(uslist,ipaddr );
	}
	byte[] deleteSalesOnScale()
	{
	    return Upload_Sale_Commond.deleteAllSalesOnScale();
	}

	///////////////////////download trace information//////////////////////////////
	String makeDownloadTraceCommondForPc(SqliteUtil sqlutil,String ipaddr) throws Exception
	{
	    return Download_trace_Commond.makeDownloadTraceCommondForPc(ipaddr);
	}
	List<byte[]> makeDownloadTraceCommondAndSave(String tracelist,SqliteUtil sqlutil,String ipaddr) throws Exception
	{
	    return Download_trace_Commond.makeTraceBytesFromString(tracelist,ipaddr);
	}
	/////////////////////// download header footer line ////////////////////////////
	byte[] makeDownloadHeadFoot(int index,String text) throws Exception
	{

	    byte[] rSendBuf = new byte[47];
	    for(int i=0;i<47;i++) rSendBuf[i]='\0';
	    byte[]  rBuf;
	    int nCnt = 0;



	    rSendBuf[nCnt++]='W';
	    rSendBuf[nCnt++]='h';

	    nCnt += 4;
	    rSendBuf[nCnt++]=',';

	    //part of commond
	    short wdData = (short)34;
	    rBuf = Common_tool.getBytes(Common_tool.swap(wdData));
	    System.arraycopy(rBuf, 0, rSendBuf, nCnt, rBuf.length);
	    nCnt += 2;

	    rSendBuf[nCnt++] = ':';

	    //data structure
	    int index_no = index;
	    rBuf = Common_tool.getBytes(Common_tool.swap(index_no));
	    System.arraycopy(rBuf, 0, rSendBuf, nCnt, rBuf.length);
	    nCnt += 4;

	    rBuf = text.getBytes("GBK");
	    System.arraycopy(rBuf, 0, rSendBuf, nCnt, rBuf.length);
	    nCnt += 30;
	    //:
	    rSendBuf[nCnt++]=':';
	    //check sum
	    rSendBuf[nCnt++]=Common_tool.getCheckSum(rSendBuf,nCnt,2);
	    //end flag
	    rSendBuf[nCnt++]=(char)0x0D;

	    return rSendBuf;
	}
}
